$(function() {
	var pictureIndex = 0;
	var totalLength = 0;
	var pictureWidth = 0;
	$('.model-self-inner ul li img').each(function(){
		totalLength += ($(this).width() + 31);
	});
	
	var boxWidth = $('.model-self-column').width();
	
	$(".next-bt").click(function() {
		if (boxWidth > totalLength) {
			$(this).attr('disabled', false);
		} else {
			var offset = $('.model-self-inner ul li img').eq(pictureIndex).width();
			pictureWidth += (offset + 31);
			$(".model-self-inner").animate({
				"left" : -pictureWidth
			});
			totalLength -= (offset + 31);
			pictureIndex++;
		}
	});
	$(".pre-bt").click(function() {
		if (pictureIndex == 0) {
			$(this).attr('disabled', false);
		} else {
			pictureIndex--;
			var offset = $('.model-self-inner ul li img').eq(pictureIndex).width();
			pictureWidth -= offset;
			$(".model-self-inner").animate({
				"left" : -pictureWidth
			});
			totalLength += offset;
		}
	});
	$(".mask").click(function() {
		$(".mask").hide();
		$(".model-big").hide();
	});
	$(".model-self-inner img").click(function() {
		var src_img = $(this).attr("src");
		var width = $(this).attr('originalWidth');
        var height = $(this).attr('originalHeight');
        if (width >= height) {
        	if (width < 660) {
        		height = 660 * (height / width);
        		width = 660;
        	}
        } else {
        	if (width < 435) {
        		height = 435 * (height / width);
        		width = 435;
        	}
        }

        $('.model-big').css({'height' : parseInt(height), 'margin-left' : parseInt(0 - (width / 2))});
        $('.model-big-inner').css('height', parseInt(height));
        $(".model-big img").attr("width", parseInt(width));
        $(".model-big img").attr("height", parseInt(height));
        $(".mask").show();
        $(".model-big img").attr("src", src_img);
        $(".model-big").fadeIn('slow');
	});

	$(".model-big img").click(function() {
		$(".mask").hide();
		$(".model-big").hide();
	});
});